關於 React 小書:將 JSX 傳入函式,再把回傳的 JSX 放到頁面


Posted by YongChenSu on 2020-12-09

將 JSX 傳入函式,再把回傳的 JSX 放到頁面

兩個 JSX 元素傳入 renderGoodWord 中,通過表達式,把該函數返回的 JSX 元素插入到頁面上。

import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import './index.css'

class Header extends Component {
  renderGoodWord (goodWord, badWord) {
    const isGoodWord = true
    return isGoodWord ? goodWord : badWord
  }

  render () {
    return (
      <div>
        <h1>
          React 小書
          {this.renderGoodWord(
            <strong> is good</strong>,
            <span> is not good</span>
          )}
        </h1>
      </div>
    )
  }
}

ReactDOM.render(
  <Header />,
  document.getElementById('root')
)


參考資源


#程式導師實驗計畫第四期 #前端 #React #react 小書 #JSX







Related Posts

Codewars Kyu 4 Python 3

Codewars Kyu 4 Python 3

[ 筆記 ] 網路基礎 - HTTP, Request, Response

[ 筆記 ] 網路基礎 - HTTP, Request, Response

軟體工程師面試資源最簡整理與技巧分享

軟體工程師面試資源最簡整理與技巧分享


Comments